import QtQuick 2.12
import QtQml 2.12
import HB.Scene3D 1.0

Item {
    anchors.fill: parent
    z: 101

    property int fadeInTimeMs: 0

    Loader {
        anchors.fill: parent
        sourceComponent: Qt.platform.os == "linux" ? undefined : debugComponent
        Component {
            id: debugComponent
            Item {
                Image { source: _dynqml.bgPath }
                onWidthChanged: {
                    children[0].x = (parent.width - children[0].width) / 2
                    children[0].y = parent.height - children[0].height
                }
            }
        }
    }

    Scene3D {
        id: scene3d
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        
        Behavior on opacity { NumberAnimation { duration: fadeInTimeMs } }
        opacity: 0
        Component.onCompleted: {
            opacity = 1
            console.log(">>>>>>>>>> Roads3D.qml::Scene3D loaded success !!!!!!!")
        }
    }

    Image {
        visible: _dynqml.zhichePngVisible
        source: visible ? _dynqml.zhichePngPath : ""
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
    }

    Rectangle {
        visible: _dynqml.fpsEnabled ? true : false
        color: "yellow"
        width: 150; height: 40
        anchors.right: scene3d.right
        anchors.top: scene3d.top
        Text {
            text: "FPS:" + _dynqml.fps
            color: "red"
            anchors.centerIn: parent
            font.pointSize: Qt.platform.os == "linux" ? 14 : 24
        }
    }

    Text {
        id: debugMsg
        visible: _dynqml.debugMsgVisible
        x: scene3d.x + 5
        y: scene3d.y + 5
        color: "red"
        font.pointSize: 14
        text: _dynqml.debugMsg
    }

    Text {
        id: featureDesc
        visible: _dynqml.displayAllFeatures ? true : false
        text: "========> 功能演示 <========"
        horizontalAlignment: Text.AlignHCenter
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 90
        font.pointSize: Qt.platform.os == "linux" ? 14 : 24
        font.bold: true
        color: "Fuchsia"

        Behavior on opacity { NumberAnimation { duration: fadeInTimeMs } }
        opacity: 0
        Component.onCompleted: opacity = 1

        Connections {
            target: _dynqml
            onFeatureChanged: {
                var feature = _dynqml.feature;
                var featureNO = "(" + feature + ")\n";
                switch (feature) {
                    case TestFeature.ROAD: featureDesc.text = featureNO + "道路线"; break;
                    case TestFeature.ALC: featureDesc.text = featureNO + "变道提醒"; break;
                    case TestFeature.DCLC: featureDesc.text = featureNO + "转向箭头"; break;
                    case TestFeature.MODEL: featureDesc.text = featureNO + "前车"; break;
                    case TestFeature.ACC_FD: featureDesc.text = featureNO + "跟车预警"; break;
                    case TestFeature.LDW: featureDesc.text = featureNO + "偏离预警"; break;
                    case TestFeature.ACC_TG: featureDesc.text = featureNO + "时距档位"; break;
                    case TestFeature.LampBrake: featureDesc.text = featureNO + "刹车灯"; break;
                    case TestFeature.LampTurn: featureDesc.text = featureNO + "转向灯"; break;
                    case TestFeature.ZhicheDoor: featureDesc.text = featureNO + "自车开门预警"; break;
                    default: featureDesc.text = "Unknown Feature"; break;
                }
            }
        }
    }
}